<template>
  <div>
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="120px"
        class="form"
      >
        <el-row :gutter="20">
          <el-col :span="12" :offset="0">
            <el-form-item label="基地关联部门" prop="deptId">
               <el-input
               disabled
                v-model="form.deptId"
                placeholder="基地部门"
              />
            </el-form-item>
            <el-form-item label="基地简称" prop="baseShortName">
              <el-input
                v-model="form.baseShortName"
                placeholder="请输入基地简称"
              />
            </el-form-item>
            <el-form-item label="基地编号" prop="baseCode">
              <el-input v-model="form.baseCode" placeholder="请输入基地编号" />
            </el-form-item>
            <el-form-item label="基地负责人" prop="baseLeader">
              <el-input
                v-model="form.baseLeader"
                placeholder="请输入基地负责人"
              />
            </el-form-item>
            <el-form-item label="基地负责人电话" prop="leaderTel">
              <el-input
                v-model="form.leaderTel"
                placeholder="请输入基地负责人电话"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12" :offset="0">
            <el-form-item label="基地全称" prop="baseName">
              <el-input v-model="form.baseName" placeholder="请输入基地全称" />
            </el-form-item>
            <el-form-item label="基地面积" prop="baseArea">
              <el-input v-model="form.baseArea" placeholder="请输入基地面积">
                <template slot="append">亩</template>
              </el-input>
            </el-form-item>
            <el-form-item label="基地海拔" prop="baseAltitude">
              <el-input
                v-model="form.baseAltitude"
                placeholder="请输入基地海拔"
              >
                <template slot="append">米</template>
              </el-input>
            </el-form-item>
            <el-form-item label="基地负责人地址" prop="baseAddress">
              <el-input
                v-model="form.baseAddress"
                placeholder="请输入基地负责人地址"
              />
            </el-form-item>
            <el-form-item label="基地坐标" prop="baseCoordinate">
              <point-select v-model="form.baseCoordinate" :isDrawLand="false"></point-select>
            </el-form-item>
          </el-col>
        </el-row>
       <el-form-item label="基地描述" prop="baseDes">
          <el-input
            v-model="form.baseDes"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="现场图片" prop="baseImg">
          <imageUpload v-model="form.baseImg" :fileSize="30" :limit="1" />
        </el-form-item>
      </el-form>
  </div>
</template>

<script>
import PointSelect from '@/views/iot/device/components/PointSelect';
import {
  getBaseinfoByDeptId,
  addBaseinfo,
  updateBaseinfo,
} from '@/api/agriculture/baseinfo';
export default {
  name: '',
  mixins: [],
  components: {PointSelect},
  props: {
      deptId:Number
  },
  data() {
    return{
            // 表单参数
      form: {},
      // 表单校验
      rules: {
        baseShortName: [
          { required: true, message: '基地简称不能为空', trigger: 'blur' },
        ],
        baseCode: [
          { required: true, message: '基地编号不能为空', trigger: 'blur' },
        ],
        baseName: [
          { required: true, message: '基地全称不能为空', trigger: 'blur' },
        ],
        baseLeader: [
          { required: true, message: '基地负责人不能为空', trigger: 'blur' },
        ],
        leaderTel: [
          {
            required: true,
            message: '基地负责人电话不能为空',
            trigger: 'blur',
          },
        ],
        baseAddress: [
          {
            required: true,
            message: '基地负责人地址不能为空',
            trigger: 'blur',
          },
        ],
        baseArea: [
          { required: true, message: '基地面积不能为空', trigger: 'blur' },
        ],
        baseAltitude: [
          { required: true, message: '基地海拔不能为空', trigger: 'blur' },
        ],
        baseImg: [
          { required: true, message: '现场图片不能为空', trigger: 'blur' },
        ],
        baseDes: [
          { required: true, message: '基地描述不能为空', trigger: 'blur' },
        ],
        remark: [{ required: true, message: '备注不能为空', trigger: 'blur' }],
        status: [{ required: true, message: '状态不能为空', trigger: 'blur' }],
        orderNum: [
          { required: true, message: '排序不能为空', trigger: 'blur' },
        ],
        baseCoordinate: [
          { required: true, message: '不能为空', trigger: 'blur' },
        ],
        deptId: [
          {
            required: true,
            message: '基地关联部门id不能为空',
            trigger: 'blur',
          },
        ],
      },
    }
  },
  computed: {},
  async created() {
      const res = await getBaseinfoByDeptId(this.deptId);
      this.form = res.data;
  },
  mounted() {},
  destroyed() {},
  methods: {
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          if (this.form.baseId != null) {
            updateBaseinfo(this.form).then((response) => {
              this.$modal.msgSuccess('修改成功');
            });
          }
          this.$emit('validate',true)
        }else{
          this.$emit('validate',false)
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
</style>
